#ifndef __LUA_SCHEDULER_H__
#define __LUA_SCHEDULER_H__

#include "lua.h"
#include <stdint.h> // For uint32_t

typedef enum {
    TASK_SUSPENDED,
    TASK_RUNNING,
    TASK_DEAD
} task_status_t;

typedef struct {
    lua_State *co;
    task_status_t status;
    int ref; // Keep a reference to the coroutine in the registry
    uint32_t wakeup_time; // Tick count for wakeup
} lua_task_t;

// Get the currently running task, needed by lua_module_mcu
lua_task_t* lua_scheduler_get_current_task(void);

// Initialize the Lua scheduler
void lua_scheduler_init(lua_State *L);

// Create a new Lua task from a function on the stack
int lua_scheduler_new_task(lua_State *L);

// Start the scheduler. This is the main loop.
void lua_scheduler_run(void);

#endif // __LUA_SCHEDULER_H__
